package burp;

import ui.Model;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by shuaidong on 2017/6/25.
 */
public class ScannerInsertPointProvider implements IScannerInsertionPointProvider {

    private IBurpExtenderCallbacks callbacks;
    private PrintWriter stdout;

    public ScannerInsertPointProvider(IBurpExtenderCallbacks callbacks,PrintWriter stdout) {

        this.callbacks = callbacks;
        this.stdout = stdout;
    }

    public List<IScannerInsertionPoint> getInsertionPoints(IHttpRequestResponse baseRequestResponse) {

        List<IScannerInsertionPoint> scannerInsertionPointList = new ArrayList<IScannerInsertionPoint>();
       IRequestInfo iRequestInfo =  this.callbacks.getHelpers().analyzeRequest(baseRequestResponse);

       List<IParameter> parameterList = iRequestInfo.getParameters();

       for (IParameter parameter:parameterList){
           if (!parameter.getName().trim().equals("")) {
               if (parameter.getType()==IParameter.PARAM_URL&& !Model.getInstanceModel().isParamInUrl()) {
                   continue;
               }
               else if (parameter.getType()==IParameter.PARAM_COOKIE&& !Model.getInstanceModel().isParamInCookies()){
                   continue;

               }
               else if (parameter.getType()==IParameter.PARAM_BODY&& !Model.getInstanceModel().isParamInCookies()){
                   continue;
               }
               InsertionPoint insertionPoint = new InsertionPoint(this.callbacks.getHelpers(), this.stdout, parameter.getName(), parameter.getValue(), baseRequestResponse, parameter.getType());
               scannerInsertionPointList.add(insertionPoint);
           }
       }

        return scannerInsertionPointList;
    }
}
